package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KMyReward;
import com.ruoyi.qsng.service.IKMyRewardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我的签到奖励Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/reward")
@Api(tags = "pc--我的签到奖励Controller")
public class KMyRewardController extends BaseController {
    @Autowired
    private IKMyRewardService kMyRewardService;

    /**
     * 查询我的签到奖励列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询我的签到奖励列表")
    public TableDataInfo list(KMyReward kMyReward) {
        startPage();
        List<KMyReward> list = kMyRewardService.selectKMyRewardDataList(kMyReward);
        return getDataTable(list);
    }

    /**
     * 导出我的签到奖励列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:export')")
    @Log(title = "我的签到奖励", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出我的签到奖励列表")
    public void export(HttpServletResponse response, KMyReward kMyReward) {
        List<KMyReward> list = kMyRewardService.selectKMyRewardList(kMyReward);
        ExcelUtil<KMyReward> util = new ExcelUtil<KMyReward>(KMyReward.class);
        util.exportExcel(response, list, "我的签到奖励数据");
    }

    /**
     * 获取我的签到奖励详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取我的签到奖励详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kMyRewardService.selectKMyRewardById(id));
    }

    /**
     * 新增我的签到奖励
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:add')")
    @Log(title = "我的签到奖励", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增我的签到奖励")
    public AjaxResult add(@RequestBody KMyReward kMyReward) {
        return toAjax(kMyRewardService.insertKMyReward(kMyReward));
    }

    /**
     * 修改我的签到奖励
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:edit')")
    @Log(title = "我的签到奖励", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改我的签到奖励")
    public AjaxResult edit(@RequestBody KMyReward kMyReward) {
        return toAjax(kMyRewardService.updateKMyReward(kMyReward));
    }

    /**
     * 删除我的签到奖励
     */
    @PreAuthorize("@ss.hasPermi('qsng:reward:remove')")
    @Log(title = "我的签到奖励", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除我的签到奖励")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kMyRewardService.deleteKMyRewardByIds(ids));
    }
}
